package com.acme.bankapp.app;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import com.acme.bankapp.server.BankServer;
import com.acme.domain.account.Account;
import com.acme.domain.account.CheckingAccount;
import com.acme.domain.bank.Bank;
import com.acme.domain.bank.Client;
import com.acme.domain.bank.Gender;
import com.acme.exceptions.AccountClosedException;
import com.acme.exceptions.ClientDuplicateException;
import com.acme.exceptions.ClientNotExistException;
import com.acme.exceptions.InjuredFileException;
import com.acme.exceptions.NotEnoughFundsException;
import com.acme.service.bank.BankService;

public class BankApplication {
	private static Bank db = new Bank();
	static BankServer bs = new BankServer(db);
	public static void main(String[] args) throws NumberFormatException, InjuredFileException, ClientDuplicateException, IOException, ClientNotExistException {

		BankService.loadClients(db, "clients.txt");
		List<Account> accounts = new ArrayList<Account>();
		accounts.add(new CheckingAccount(20, 30));
		Client clientPetrova = new Client(accounts, "Petrova", Gender.FEMALE);
		BankService.addClient(db, clientPetrova);
		
		while(true) {
			try {
				bs.run();
			} catch (ClientDuplicateException | ClientNotExistException | NumberFormatException | NotEnoughFundsException | AccountClosedException e) {
				e.printStackTrace();
			}
		}
	}
}
